home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 14 / CU Amiga Magazine's Super CD-ROM 14 (1997)(EMAP Images)(GB)(Track 1 of 3)[!][issue 1997-09].iso / CUCD / Programming / Blitz2 / BlitzFaq / FaqLists / Messageports.txt < prev    next >
Encoding:
Text File  |  1996-09-03  |  1.6 KB  |  52 lines

  1. ; *** make 'blitzlibs:amigalibs.res' resident ***
  2. ;
  3. ; get delay from user
  4. Print "Enter seconds to wait..."
  5. waittime.w = Edit(5)
  6. ; create a message port for the timer.device to use..
  7. *TimerMP.MsgPort = CreateMsgPort_()
  8. If *TimerMP
  9.   ; if all went well....
  10.   *TimerIO.timerequest = CreateIORequest_ (*TimerMP,SizeOf .timerequest)
  11.   ; ...then create a time request
  12.   If *TimerIO
  13.     ; and hopefully....
  14.     err = OpenDevice_ ("timer.device",#UNIT_MICROHZ,*TimerIO,0)
  15.     ; ...finally open the timer device.
  16.     If err Then NPrint "Error opening timer.device" : End
  17.     ; Warn if failed!
  18.     *TimerIO\tr_node\io_Command = #TR_ADDREQUEST
  19.     ; add the request to the timer's list
  20.     *TimerIO\tr_time\tv_secs = waittime
  21.     ; set the delay
  22.     *TimerIO\tr_time\tv_micro = 0
  23.     ; we only want whole seconds
  24.     SendIO_ *TimerIO
  25.     ; send the request to the timer.device
  26.     NPrint "Now waiting for ",waittime," seconds..."
  27.     ; show user what's happening
  28.     WaitPort_ *TimerMP
  29.     ; wait for the timer to signal us...
  30.     Repeat
  31.       *TimerMsg.Message = GetMsg_(*TimerMP)
  32.       ; get the messages from msgport
  33.     Until *TimerMsg = 0
  34.     ; until there's none left. You must make sure you have ALL msg's
  35.     ; or the OS will lock up for sure.
  36.     NPrint waittime," second(s) elapsed ;)"
  37.     ; tell user that all went well
  38.     CloseDevice_ (*TimerIO)
  39.     ; close the timer.device
  40.     DeleteIORequest_ (*TimerIO)
  41.     ; delete the request
  42.     DeleteMsgPort_ (*TimerMP)
  43.     ; and close the msgport
  44.   Else
  45.     NPrint "Error creating IORequest"
  46.     ; warn if failed
  47.   EndIf
  48. Else
  49.   NPrint "Error creating message port"
  50.   ; warn if failed
  51. EndIf
  52. End